package com.bb.blog.security.service;

import com.bb.blog.security.dao.ClientDetailsMapper;
import com.bb.blog.security.model.BbClientDetails;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.stereotype.Service;


/**
 * todo 添加对于状态的判断并抛出异常
 */
@Service("myClientService")
@RequiredArgsConstructor
@CacheConfig(cacheNames = "bb.blog.security.client")
public class ClientDetailsServiceImpl implements ClientDetailsService {
    private final ClientDetailsMapper clientDetailsMapper;

    @Cacheable( key = "#clientId")
    @Override
    public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
        BbClientDetails clientDetails = clientDetailsMapper.selectByClientId(clientId);
        return clientDetails;

    }

    @CacheEvict( key = "#clientId")
    public void clearCache(String clientId){}
}
